﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Practices.Mobile.Configuration;
using Microsoft.Practices.Mobile.DisconnectedAgent;
using Microsoft.Practices.Mobile.DisconnectedAgent.WebService.ConfigurationCredentialService;
using System.Net;
using Microsoft.Practices.TestUtilities;

namespace Microsoft.Practices.Mobile.DisconnectedAgent.Tests
{
    [TestClass]
    public class ConfigurationCredentialServiceFixture
    {
        [TestInitialize]
        public void InitializeConfigurationManager()
        {
            ConfigurationManager.ClearCache();
            ConfigurationManager.ConfigFileName = "App.config";
        }


        [TestMethod]
        public void ConfigurationCredentialsFollowsAppConfigFile()
        {
            IWSCredentialService svc = CreateConfigurationCredentialService();

            Assert.AreEqual(null, svc.GetCredential("NoCredsAccount"));
            Assert.AreEqual("UP", svc.GetCredential("UserAndPasswordAccount").UserName);
            Assert.AreEqual("PU", svc.GetCredential("UserAndPasswordAccount").Password);
            Assert.AreEqual("UPD", svc.GetCredential("UserAndPasswordAndDomainAccount").UserName);
            Assert.AreEqual("DPU", svc.GetCredential("UserAndPasswordAndDomainAccount").Password);
            Assert.AreEqual("D", svc.GetCredential("UserAndPasswordAndDomainAccount").Domain);
        }

        internal ConfigurationCredentialService CreateConfigurationCredentialService()
        {
            ConfigurationCredentialService service = null;
            using (TestResourceFile resFile = new TestResourceFile(this, @"App.config"))
            {
                service = ConfigurationCredentialService.CreateFromConfiguration();
            }
            return service;
        }

	
    }
}
